#include <iostream>
#include <future>
#include <memory>
#include <thread>
using namespace std;

int Add(int a,int b)
{
    cout << "into Add" << endl;
    return a + b;
}

int main()
{
    //封装任务，定义很像functional,但返回的是future对象
    auto pt = make_shared<packaged_task<int(int,int)>>(Add);

    //获取future对象
    future<int> f = pt->get_future();

    
    //执行任务
    thread t([pt](){
        (*pt)(1,2);
    });

    //线程等待
    t.join();

    cout << f.get() << endl; 
}
